﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace BiessesXmlReader
{
    public class Pattern
    {
        public string id { get;private set; }
        public string BrdNo { get;private set; }
        public int Rep { get;private set; }
        public int Cyc { get;private set; }
        public double UL { get;private set; }
        public double UW { get;private set; }
        public string TCyc { get;private set; }
        public string TStart { get;private set; }
        public string TStop { get;private set; }
        public string TMan { get;private set; }
        public string TLongMB { get;private set; }
        public string TCrossMB { get;private set; }
        public string CutLen1 { get;private set; }
        public string Prod { get;private set; }
        public string HProd { get;private set; }
        public string Lost { get;private set; }
        public string Kerf { get;private set; }
        public string Trim { get;private set; }
        public string Scrap { get;private set; }
        public string Str { get;private set; }
        public string Chk { get;private set; }
        public static List< Pattern >GetPatterns(XElement x)
        {
           List< Pattern> ps = new List< Pattern>();
           List<XElement> xp = xp = x.Elements("Pattern").ToList();
            foreach (var p in xp)
            {
                Pattern pat = new Pattern();
                pat.id = (p.Attribute("id") == null) ? string.Empty : p.Attribute("id").Value;
                pat.BrdNo = (p.Attribute("BrdNo") == null) ? string.Empty : p.Attribute("BrdNo").Value;
                pat.Rep = (p.Attribute("Rep") == null) ?0 :int.Parse( p.Attribute("Rep").Value);
                pat.Cyc = (p.Attribute("Cyc") == null) ? 0 :int.Parse( p.Attribute("Cyc").Value);
                pat.UL = (p.Attribute("UL") == null) ?0 :double.Parse( p.Attribute("UL").Value);
                pat.UW = (p.Attribute("UW") == null) ? 0 :double.Parse( p.Attribute("UW").Value);
                pat.TCyc = (p.Attribute("TCyc") == null) ? string.Empty : p.Attribute("TCyc").Value;
                pat.TStart = (p.Attribute("TStart") == null) ? string.Empty : p.Attribute("TStart").Value;
                pat.TStop = (p.Attribute("TStop") == null) ? string.Empty : p.Attribute("TStop").Value;
                pat.TMan = (p.Attribute("TMan") == null) ? string.Empty : p.Attribute("TMan").Value;
                pat.TLongMB = (p.Attribute("TLongMB") == null) ? string.Empty : p.Attribute("TLongMB").Value;
                pat.TCrossMB = (p.Attribute("TCrossMB") == null) ? string.Empty : p.Attribute("TCrossMB").Value;
                pat.CutLen1 = (p.Attribute("CutLen1") == null) ? string.Empty : p.Attribute("CutLen1").Value;
                pat.Prod = (p.Attribute("Prod") == null) ? string.Empty : p.Attribute("Prod").Value;
                pat.HProd = (p.Attribute("HProd") == null) ? string.Empty : p.Attribute("HProd").Value;
                pat.Lost = (p.Attribute("Lost") == null) ? string.Empty : p.Attribute("Lost").Value;
                pat.Kerf = (p.Attribute("Kerf") == null) ? string.Empty : p.Attribute("Kerf").Value;
                pat.Trim = (p.Attribute("Trim") == null) ? string.Empty : p.Attribute("Trim").Value;
                pat.Scrap = (p.Attribute("Scrap") == null) ? string.Empty : p.Attribute("Scrap").Value;
                pat.Str = (p.Attribute("Str") == null) ? string.Empty : p.Attribute("Str").Value;
                pat.Chk = (p.Attribute("Chk") == null) ? string.Empty : p.Attribute("Chk").Value;
                ps.Add(pat);
            }
            return ps;

        }
    }
}
